package com.wn.common.jwt;

import cn.hutool.jwt.JWT;
import cn.hutool.jwt.JWTUtil;
import cn.hutool.jwt.signers.JWTSigner;
import cn.hutool.jwt.signers.JWTSignerUtil;
import org.springframework.core.io.ClassPathResource;
import org.springframework.security.rsa.crypto.KeyStoreKeyFactory;

import java.security.KeyPair;
import java.util.HashMap;
import java.util.Map;

/**
 * @author yellow Docter
 * @date 2023 -02-27
 * @desc
 */
public class Demo02Jwt {

    public static void main(String[] args) {

        Map<String, Object> map = new HashMap<>();

        map.put("userId", 12);
        map.put("phone", "18566230011");

        //创建一个token
        JwtTemplate jwtTemplate = new JwtTemplate();
        String token = jwtTemplate.createToken(map);
        System.out.println("token = " + token);

        //校验 token
        boolean b = jwtTemplate.verifyToken(token);
        System.out.println("b = " + b);

        //解析token
        String phone = (String) jwtTemplate.parseToken(token, "phone");
        System.out.println("phone = " + phone);
    }

}
